//
//  PushConfig.swift
//  cangchu
//
//  Created by kang on 2021/11/30.
//

import Foundation
import UIKit

public class PushConfig{
    
    //应用信息 绑定
    public static var meAppid:String?
    public static var meSecretKey:String?
    
    //本地配置
    public static var isSound:Bool = true//是否响铃
    public static var isShowNotify:Bool = true//是否显示通知
    
    private static var localToken:String?
    
    public static func createToken()->String{
        var deviceStr:String = (UIDevice.current.identifierForVendor?.uuidString)!
        let timeStamp = Int(Date().timeIntervalSince1970)
        deviceStr.append(contentsOf: String(timeStamp))
        let token = deviceStr.md5
        PushConfig.localToken = token
        UserDefaults.standard.set(token, forKey: "local_token")
        return token
    }
    
    public static func getLocalToken()->String{
        var token:String!
        if ((PushConfig.localToken?.isEmpty) == nil){
            token = createToken()
        }else{
           token = UserDefaults.standard.string(forKey: "local_token")
        }
        return token
    }
    
    public static func refreshToken()->String{
        return createToken()
    }
}
